
log:= thirdparty/log.c thirdparty/log.h
CC:= gcc
includepath:= -Ithirdparty -Iapp -Iota -Idaemon

lib:=	-lpaho-mqtt3c -lmodbus -lcurl   -lcrypto

# -g 开启gdb的debug调试（生成的二进制文件中包含调试信息）
# -O0 禁用优化（确保调试一致性）
# -Wall 显示所有警告
CFLAGS := -g -O0 -Wall

common:= app/app_common.c app/app_common.h
json:= thirdparty/cJSON.c thirdparty/cJSON.h

message:= app/app_message.c app/app_message.h
mqtt:= app/app_mqtt.c app/app_mqtt.h
pool:= app/app_pool.c app/app_pool.h

buffer:= app/app_buffer.c app/app_buffer.h
modbus:= app/app_modbus.c app/app_modbus.h

device:= app/app_device.c app/app_device.h
runner:= app/app_runner.c app/app_runner.h

curl:= ota/ota_http_curl.c ota/ota_http_curl.h
version:=ota/ota_version.c ota/ota_version.h

daemon:= daemon/daemon_process.c  daemon/daemon_process.h  daemon/daemon_sub_process_monitor.h daemon/daemon_sub_process_monitor.c

all:= $(daemon) $(ota) $(runner)  $(curl) $(version)  $(device) $(log) $(modbus) $(buffer) $(pool) $(mqtt) $(message) $(common) $(json)

app_name:= gateway

 

clean:
	rm -f $(app_name)


test_common:test/test_common.c $(common) $(log)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath)
	./$@
	rm $@

test_message:test/test_message.c $(message) $(log) $(json)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath)
	#./$@
	#rm $@

test_mqtt:test/test_mqtt.c $(mqtt) $(log)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath) $(lib)
	./$@
	rm $@

test_pool:test/test_pool.c   $(log) $(pool)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath)
	./$@
	rm $@

test_buffer:test/test_buffer.c $(log) $(buffer)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath)
	./$@
	rm $@

test_modbus:test/test_modbus.c $(log) $(modbus)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath) $(lib)
	./$@
	rm $@


test_device:test/test_device.c $(device) $(log) $(modbus) $(buffer) $(pool) $(mqtt) $(message) $(common) $(json)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath) $(lib)
	./$@
	rm $@

test_curl:test/test_curl.c  $(curl)
	$(CC)  $(CFLAGS) $^ -o $@    $(includepath) $(lib)
	./$@
	rm $@


test_update:main.c   $(all)
	$(CC)  $(CFLAGS) $^ -o $(app_name)    $(includepath)  $(lib)
	#./$(app_name) update
	#rm $(app_name)


main:main.c   $(all)
	$(CC)  $(CFLAGS) $^ -o $(app_name)    $(includepath)  $(lib)
	./$(app_name) daemon
	#rm $(app_name)

clean:
	rm -f $(app_name)


CROSS_COMPILE:=./toolchain/bin/arm-linux-gnueabihf-gcc 

SYSROOT:= --sysroot=./sysroot

app_peer := root@192.168.31.29

cross_compile: main.c $(all)
	-$(CROSS_COMPILE) -o $(app_name) $^  $(includepath)  $(lib) $(SYSROOT)
	#-scp $(app_name)   $(app_peer):/usr/bin/$(app_name)
	#rm -f  $(app_name)

init_shell:
	scp ./init/S99gateway  $(app_peer):/etc/init.d/S99gateway
